package com.czxy.tanhua.autoconfig.template;

import com.baidu.aip.face.AipFace;
import com.czxy.tanhua.autoconfig.properties.FaceProperties;
import org.json.JSONObject;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @Author 爱吃豆的土豆、
 * @Date 2023/3/31 10:27
 */
@Component
public class FaceTemplate {
    @Resource
    private AipFace aipFace;
    private FaceProperties faceProperties;
    public FaceTemplate(FaceProperties faceProperties){
        this.faceProperties = faceProperties;
    }

    public boolean FaceUtils(String imageurl){
        
        String imageType = "URL";


            // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
//        options.put("liveness_control", "LOW");

        // 人脸检测
        JSONObject res = aipFace.detect(imageurl, imageType, options);
        Integer error_code = (Integer) res.get("error_code");
        return error_code == 0;
    }
}
